#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDebug>
#include <QThread>
#include <QFile>
#include <QTextCodec>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>

class Thread: public QThread
{
public:
	void run()
	{
//		this->encryption("feixin158");
//		this->open_night();
//		qDebug() << QThread::currentThread();
		this->login();
	}
	void encryption(QByteArray password_data)
	{
		QByteArray password_head = "axy_";
		password_data = password_head + password_data;
		password_data = QCryptographicHash::hash(password_data,QCryptographicHash::Md5).toHex();
		qDebug() << password_data.data();
	}
	void open_night()
	{
		QFile file(":/night.txt");
		file.open(QIODevice::ReadOnly);
		while(!file.atEnd())
		{
			QByteArray file_data = file.readLine();
			QString str = QTextCodec::codecForName("utf-8")->toUnicode(file_data.simplified());
			qDebug() << str.section(":",0,0) << str.section(":",1,1);
		}
	}
	void login()
	{
		QNetworkRequest request;
		request.setUrl(QUrl("http://181.214.233.174/"));
//		request.setRawHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
//		request.setRawHeader("Host", "app.zhidiantianxia.cn");
//		request.setRawHeader("Connection", "keep-alive");
//		request.setRawHeader("Accept", "*/*");
		QNetworkAccessManager *manager = new QNetworkAccessManager();
		QByteArray data;
		data.append("appVersion=1.6.9&"
					"deviceToken=B5ECB0B3-468B-460A-BA22-1D2B3F773868&"
					"mobileSystem=14.6&"
					"mobileVersion=iPhone11%2C6&"
					"password=4a029f883384ea341713d79918e3cad6&"
					"phone=18860361934");
		qDebug() << data;
		QNetworkReply *reply = manager->get(request);
		QEventLoop loop;
		QObject::connect(reply,SIGNAL(finished()),&loop,SLOT(quit()));
		QObject::connect(reply,&QNetworkReply::finished,[=](){
			QString str = QTextCodec::codecForName("utf-8")->toUnicode(reply->readAll());
			qDebug() << str.simplified();
			reply->deleteLater();
		});
		loop.exec();
	}
};
class Request
{
public:
	Request()
	{
		t1.start();
	}
	~Request()
	{
		t1.quit();
		t1.wait();
	}
	Thread t1;
};

int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	Request r;
	return a.exec();
}
